package client

func (c *Client) onResponse(m *Pack) {
	id := m.Id
	waiter, ok := c.waiters[id]
	if ok {
		waiter.cancelTimeout <- true
		waiter.fn(id, waiter.msg, m.Msg)
		waiter.dispose()
		delete(c.waiters, id)
	} else {
		c.delegate.onWarn("waiter with id: " + id + " not found")
	}
}

func (c *Client) response(id string, to *json.Json, msg *json.Json) {
	msg.Set("to", to)
	m := NewPackWithId(id, "response", msg)
	c.sendPack(m, true)
}
